#include <iostream>

using namespace std;

class Person{
public:
	string name;
	int* age = NULL;
	Person(string name, int age){
		this->age = new int(age);
		this->name = name;
	}
	// 显示定义了 拷贝构造函数 编译器就不会默认生成其他构造函数，必须手动定义
	// 一旦手动定义了 拷贝构造函数，就必须自己进行对每个属性进行复制操作，编译器不再帮你搞了
	Person(const Person& person){
		cout << "person() copy init" << endl;
		this->name = person.name;
		// 浅拷贝
		this->age = person.age;
		// 深拷贝
		//this->age = new int(*person.age);
	}
	~Person(){
		cout<<"destory method invoked." << endl;
		delete age;
	}
	void say(){
		cout << "say() before. " << endl;
		cout << "person age is " << age << " name is " << name << endl;
	}
};
void func(){
	int a=13;
	Person p("王颖颖",a);
	p.say();
	
	Person p2(p);
	cout<< "p2.say() will be invoked." << endl<<endl;
	
	cout << "p.age: " << p.age << " name is " << p.name << endl; 
	cout << "p2.age: " << p2.age << " name is " << p2.name << endl; 
	p2.say();
}
// g++ creat.cpp Dog.cpp -o creat.exe -std=c++11
int main(){
	func();
}